package row
import (
"github.com/K-Phoen/grabana/alert"
"github.com/K-Phoen/grabana/gauge"
"github.com/K-Phoen/grabana/graph"
"github.com/K-Phoen/grabana/heatmap"
"github.com/K-Phoen/grabana/logs"
"github.com/K-Phoen/grabana/singlestat"
"github.com/K-Phoen/grabana/stat"
"github.com/K-Phoen/grabana/table"
"github.com/K-Phoen/grabana/text"
"github.com/K-Phoen/grabana/timeseries"
"github.com/K-Phoen/sdk"
)
type Option func (row *Row ) error
type Row struct {
builder *sdk .Row
alerts []*alert .Alert
}
func New (board *sdk .Board , title string , options ...Option ) (*Row , error ) {
panel := &Row {builder : board .AddRow (title )}
for _ , opt := range append (defaults (), options ...) {
if err := opt (panel ); err != nil {
return nil , err
}
}
return panel , nil
}
func defaults() []Option {
return []Option {
ShowTitle (),
}
}
func (row *Row ) Alerts () []*alert .Alert {
return row .alerts
}
func WithGraph (title string , options ...graph .Option ) Option {
return func (row *Row ) error {
panel , err := graph .New (title , options ...)
if err != nil {
return err
}
row .builder .Add (panel .Builder )
if panel .Alert == nil {
return nil
}
if panel .Builder .Datasource != nil {
panel .Alert .Datasource = panel .Builder .Datasource .LegacyName
}
row .alerts = append (row .alerts , panel .Alert )
return nil
}
}
func WithTimeSeries (title string , options ...timeseries .Option ) Option {
return func (row *Row ) error {
panel , err := timeseries .New (title , options ...)
if err != nil {
return err
}
row .builder .Add (panel .Builder )
if panel .Alert == nil {
return nil
}
if panel .Builder .Datasource != nil {
panel .Alert .Datasource = panel .Builder .Datasource .LegacyName
}
row .alerts = append (row .alerts , panel .Alert )
return nil
}
}
func WithGauge (title string , options ...gauge .Option ) Option {
return func (row *Row ) error {
panel , err := gauge .New (title , options ...)
if err != nil {
return err
}
row .builder .Add (panel .Builder )
return nil
}
}
func WithLogs (title string , options ...logs .Option ) Option {
return func (row *Row ) error {
panel , err := logs .New (title , options ...)
if err != nil {
return err
}
row .builder .Add (panel .Builder )
return nil
}
}
func WithSingleStat (title string , options ...singlestat .Option ) Option {
return func (row *Row ) error {
panel , err := singlestat .New (title , options ...)
if err != nil {
return err
}
row .builder .Add (panel .Builder )
return nil
}
}
func WithStat (title string , options ...stat .Option ) Option {
return func (row *Row ) error {
panel , err := stat .New (title , options ...)
if err != nil {
return err
}
row .builder .Add (panel .Builder )
return nil
}
}
func WithTable (title string , options ...table .Option ) Option {
return func (row *Row ) error {
panel , err := table .New (title , options ...)
if err != nil {
return err
}
row .builder .Add (panel .Builder )
return nil
}
}
func WithText (title string , options ...text .Option ) Option {
return func (row *Row ) error {
panel , err := text .New (title , options ...)
if err != nil {
return err
}
row .builder .Add (panel .Builder )
return nil
}
}
func WithHeatmap (title string , options ...heatmap .Option ) Option {
return func (row *Row ) error {
panel , err := heatmap .New (title , options ...)
if err != nil {
return err
}
row .builder .Add (panel .Builder )
return nil
}
}
func ShowTitle () Option {
return func (row *Row ) error {
row .builder .ShowTitle = true
return nil
}
}
func HideTitle () Option {
return func (row *Row ) error {
row .builder .ShowTitle = false
return nil
}
}
func RepeatFor (variable string ) Option {
return func (row *Row ) error {
row .builder .Repeat = &variable
return nil
}
}
func Collapse () Option {
return func (row *Row ) error {
row .builder .Collapse = true
return nil
}
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .